//**************************************************
//	Digit Widgets Spiral Module
// 	Object Spiral Manipulation 
//	Made to be called from Hyperlinked Digit_Widgets Script
//
// Version 3.0 - 09/12/01 - Added Animation Script to Widgets
//	Version 3.1 - 09/15/01 - Updated with Advanced and Standard Animation Scripts
//**************************************************
<zscriptinsert,"Digit_Widgets_Common.txt">
[PD]
[FontSetColor,255,200,0]Stroke Object Functions[FontSetColor,160,160,160]
[PD]
[VarDef,numpts,0]
[VarDef,Minh,0]
[VarDef,Maxh,0]
[VarDef,Minv,0]
[VarDef,Maxv,0]
[VarDef,MaxDeltaH,0]
[VarDef,MaxDeltaV,0]
[VarDef,cnt,0]
[VarDef,ox,0]
[VarDef,oy,0]
[VarDef,ex,0]
[VarDef,ey,0]
[VarDef,Sdist,0]
[VarDef,ssize,0]
[VarDef,Zinit,0]
[VarDef,zfinis,0]
[VarDef,zdelta,0]
[VarDef,zsize,0]
[VarDef,Zorigin,0]
[VarDef,ztmp,0]
[VarDef,ScurrZ,0]
[VarDef,dangle,0]
[VarDef,SelTool]
[VarDef,Mrk1,1]
[VarDef,Mrk2,2]
[VarDef,mcntr,0]
[VarDef,mptr,1]
[VarDef,pixolz,0]
[VarDef,pixcnt,0]
[iSlider,"SizeIncr",0,1,0,360,"Select Angle Increment ",[VarSet,ssize,zscript:SizeIncr],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"ZStart",0,1,-4000,4000,"Select Starting Z ",[VarSet,Zinit,zscript:ZStart],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"ZEnd",0,1,-4000,4000,"Select Ending Z ",[VarSet,zfinis,zscript:ZEnd],0,[TextCalcWidth,SizeIncr4123]]
[IButton,"ZPicker ","Pick Zstart and Zend by draggin XYZ Pixol on Canvas",
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	[RoutineCall,PixolLook,Hval1,Vval1,1,Zval1,dummy,dummy,dummy]
	[Iset,zscript:Zstart,Zval1]
	[VarSet,Zinit,Zval1]
	[RoutineCall,PixolLook,Hval2,Vval2,1,Zval2,dummy,dummy,dummy]
	[Iset,zscript:ZEnd,Zval2]
	[VarSet,Zfinis,Zval2]
]
//[iSlider,"ZTool",0,1,0,11,"Select ZTool ",[VarSet,SelTool,zscript:Ztool],0,[TextCalcWidth,SizeIncr4123]]
[IButton,"ZTool","Set Object that you wish to use",
	[note,"Selecting Tool....",,-1]
	[VarSet,SelTool,[IGet,TOOL:iteminfo]]
	[note,SelTool,,1]
]
[iSwitch,"DepthSizeit",0,"Size to Position",
	[if,zscript:DepthSizeit,
		[ISetStatus,zscript:UserPoint_1,0]
		[ISetStatus,zscript:UserPoint_2,0]
		[IDisable,zscript:Moveto1]
		[IDisable,zscript:Moveto2]
	]
	[if,zscript:RotSizeit,
		[IToggle,zscript:RotSizeit]
	]

] 
[iSwitch,"RotSizeit",0,"Size to UserPoint",
	[if,zscript:RotSizeit,
		[ISetStatus,zscript:UserPoint_1,1]
		[ISetStatus,zscript:UserPoint_2,1]
		[IEnable,zscript:Moveto1]
		[IEnable,zscript:Moveto2]
	]
	[if,zscript:DepthSizeit,
		[IToggle,zscript:DepthSizeit]
	]
] 
//[iSwitch,"UserZ",0,"Use UserPoint to set Z",
//	[if,zscript:UserZ,
//		[Iset,zscript:ZStart,Spointz(0)]
//		[Iset,zscript:ZEnd,Spointz(1)]
//		[VarSet,Zinit,Spointz(0)]
//		[VarSet,Zfinis,Spointz(1)]
//	]
//]
[iSwitch,"SConformit",0,"Set Z to Canvas"]
[iSwitch,"SNormalit",0,"Set Rotation to the normals on the canvas"]
[iButton,"C-ShiftAxis","Change RGB Axis for Shifting Color",
	[VarInc,Aptr]
	[if,Aptr=3,[VarSet,Aptr,0]]
	[if,Aptr=0,	[note,"XYZ = RGB",,1]]
	[if,Aptr=1,	[note,"XYZ = GBR",,1]]
	[if,Aptr=2,	[note,"XYZ = BRG",,1]]
		
]
[iSwitch,"S-ShiftColor",0,"Set Shift colors"]
[iSwitch,"SColorit",0,"Set color to Canvas"]
[iSwitch,"SPointit",0,"Rotate Object to point at NosePoint"] 

[iSwitch,"SLastPoint",0,"Rotate Object to point at Last Point drawn",
	//there is a problem with the first move in that what is the last move? so I will help this situation by doing this
	[if,[isDisabled,transform:move],
		//if no object is selected then make it the current pointer coords
		[VarSet,kx,curmX]
		[VarSet,ky,curmY]
		[VarSet,kz,curmZ]
	,//else
		//make it the current object coords
		[TransformGet,kx,ky,kz]
	]
] 

[PD]
[iButton," UserPoint_1 ","Load Current Object Size and Rotation to use in Stroke",
	[TransformGet,SpointX(0),SpointY(0),SpointZ(0),SpointXS(0),SpointYS(0),SpointZS(0),SpointXR(0),SpointYR(0),SpointZR(0)]
//	[if,zscript:UserZ,
//		[Iset,zscript:ZStart,Spointz(0)]
//		[VarSet,Zinit,Spointz(0)]
//	]
,1
]//End Load Point 1

[iButton," Moveto1 ","Load Current Object Position to UserPoint_1",
	[TransformSet,SpointX(0),SpointY(0),SpointZ(0),SpointXS(0),SpointYS(0),SpointZS(0),SpointXR(0),SpointYR(0),SpointZR(0)],1
]

[iButton," UserPoint_2 ","Load Current Object Size and Rotation to use in Stroke",
	[TransformGet,SpointX(1),SpointY(1),SpointZ(1),SpointXS(1),SpointYS(1),SpointZS(1),SpointXR(1),SpointYR(1),SpointZR(1)]
//	[if,zscript:UserZ,
//		[Iset,zscript:ZEnd,Spointz(1)]
//		[VarSet,Zfinis,Spointz(1)]
//	]
,1

]//End Load Point 2

[iButton," Moveto2 ","Load Current Object Position to UserPoint_2",
	[TransformSet,SpointX(1),SpointY(1),SpointZ(1),SpointXS(1),SpointYS(1),SpointZS(1),SpointXR(1),SpointYR(1),SpointZR(1)],1
]
[VarDef,ccntr,0]

[iButton," DoObjStroke ","Look at Stroke Data",
	[VarSet,Zinit,zscript:Zstart]
	[VarSet,Zfinis,zscript:ZEnd]
//	[VarSet,theStroke,[StrokeGetLast]] //get the last drawn stroke
	[VarSet,numpts,[StrokeGetInfo,theStroke,0]]
	[VarSet,Zdelta,Zfinis-Zinit]
	[VarSet,zsize,Zdelta/numpts]
	[VarSet,Zorigin,Zinit]
	[VarSet,Pixcnt,0]

	//[VarSet,Minh,[StrokeGetInfo,theStroke,4]]
	//[VarSet,Maxh,[StrokeGetInfo,theStroke,6]]
	//[VarSet,Minv,[StrokeGetInfo,theStroke,5]]
	//[VarSet,Maxv,[StrokeGetInfo,theStroke,7]]
	//[VarSet,MaxDeltaH,[StrokeGetInfo,theStroke,10]]
	//[VarSet,MaxDeltaV,[StrokeGetInfo,theStroke,11]]

	// got to get how much time the number of iterations are
	[if,[IGet,zscript:RotSizeit],
		[VarSet,mcntr,1.0/numpts]	
		[VarSet,mptr,1]	
		//make sure that this is updated as switch only does it once
//		[if,zscript:UserZ,
//			[Iset,zscript:ZStart,Spointz(0)]
//			[Iset,zscript:ZEnd,Spointz(1)]
//			[VarSet,Zinit,Spointz(0)]
//			[VarSet,Zfinis,Spointz(1)]
//		]
	]
	
	[VarSet,cnt,0]
	//get origin
	[VarSet,ox,[StrokeGetInfo,theStroke,1,0]]
	[VarSet,oy,[StrokeGetInfo,theStroke,2,0]]

	[ISet,Tool:ItemInfo,SelTool]
	
	//put tool on the canvas
	[canvasclick,ox,oy,ox+10,oy+10]
	//Size it accordingly
	[TransformSet,ox,oy,Zorigin,ssize,ssize,ssize]
	[if,[iGet,zscript:DepthSizeit],
		[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
		[RoutineCall,DepthCalc]
	]//Endif
	//initialize gradient variables if needed
	[if,[iGet,zscript:S-ShiftColor],
		[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
		[RoutineCall,ShiftColor,IcurrX,icurrY,IcurrZ,aptr]
	]
	[if,[iGet,zscript:SColorit],
		[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
		[RoutineCall,ZcolorCalc,IcurrX,IcurrY,IcurrZ]
	]

	//snapit
	[IPress,Transform:Snapshot]
	//draw loop distance must be greater than size
	[loop,numpts,
		[VarSet,ex,[StrokeGetInfo,theStroke,1,cnt]]
		[VarSet,ey,[StrokeGetInfo,theStroke,2,cnt]]

		//check distance
		[RoutineCall,GetDistance,ox,ex,oy,ey]
		//make sure does the last one
		[if,Pixcnt > ssize,
			[VarSet,Pixcnt,0]	//reset counter
//		[if,DistToMark>ssize,

			//use pixol to get z depth
			[if,[IGet,zscript:SConformit],
				[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS,currxr,curryr,currzr]
				[VarSet,pixolz,[PixolPick,1,ex,ey]]
				[if,[IGet,zscript:SNormalit],
					[VarSet,pkx,[pixolPick,6,ex,ey]]
					[VarSet,pky,[pixolPick,7,ex,ey]]
					[VarSet,pkz,[pixolPick,8,ex,ey]]
					[VarSet,pkx,pkx*20]
					[VarSet,pky,pky*20]
					[VarSet,pkz,pkz*20]
					[VarSet,pkx,ex+pkx]
					[VarSet,pky,ey+pky]
					[VarSet,pkz,pixolz+pkz]

					[routineCall,PointFromTo,ex,ey,pixolz,pkx,pky,pkz,Xangle,Yangle]
					[transformSet,,,,,,,Xangle,Yangle,currZR]
				]
				[VarSet,Zinit,pixolz]
			]

			//big enough so put it here
			[TransformSet,ex,ey,Zinit]

			[if,[iGet,zscript:DepthSizeit],
				[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
				[RoutineCall,DepthCalc]
			,//Else
				[if,[IGet,zscript:RotSizeit],
					[VarSet,crecurse,mcntr*mptr]
					[VarSet,resultxs,[Interpolate,crecurse,SpointXS(0),SpointXS(1)]]
					[VarSet,resultys,[Interpolate,crecurse,SpointYS(0),SpointYS(1)]]
					[VarSet,resultzs,[Interpolate,crecurse,SpointZS(0),SpointZS(1)]]
					[VarSet,resultxr,[Interpolate,crecurse,SpointXR(0),SpointXR(1)]]
					[VarSet,resultyr,[Interpolate,crecurse,SpointYR(0),SpointYR(1)]]
					[VarSet,resultzr,[Interpolate,crecurse,SpointZR(0),SpointZR(1)]]
					[TransformSet,,,,resultxs,resultys,resultzs,resultxr,resultyr,resultzr]
				]
			]//Endif
		
			[if,[IGet,zscript:SPointit],
				[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
				[routineCall,PointFromTo,ICurrX,ICurrY,ICurrZ,curmX,curmY,curmZ,Xangle,Yangle]
				[transformSet,,,,,,,Xangle,Yangle,CurrZR]
				[VarSet,pixolz,[PixolPick,1,IcurrX,IcurrY]]
				[TransformSet,,,pixolz]
			]
		
			[if,[IGet,zscript:SLastPoint],
				[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS,currxr,curryr,currzr]
				[routineCall,PointFromTo,IcurrX,IcurrY,IcurrZ,kx,ky,kz,Xangle,Yangle]
				[transformSet,,,,,,,Xangle,Yangle,currzr]
				[VarSet,KX,IcurrX]
				[VarSet,KY,IcurrY]
				[VarSet,KZ,IcurrZ]
			]

			[if,[iGet,zscript:S-ShiftColor],
				[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
				[RoutineCall,ShiftColor,IcurrX,icurrY,IcurrZ,aptr]
			]
			[if,[IGet,zscript:SColorit],
				[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
				[RoutineCall,ZcolorCalc,IcurrX,IcurrY,IcurrZ]
			]

			[IPress,Transform:Snapshot]
			//make this the new start
			[VarSet,ox,ex]
			[VarSet,oy,ey]
			//increment Z 
			[VarSet,ztmp,zsize*cnt]
			[VarSet,Zinit,Zorigin+ztmp]
		]

		//update mptr as we find the next point
		[VarInc,mptr]
		[VarInc,cnt]
		[VarInc,Pixcnt]
	]//endloop
	//make sure end is done	
	[VarSet,ex,[StrokeGetInfo,theStroke,1,numpts]]
	[VarSet,ey,[StrokeGetInfo,theStroke,2,numpts]]
	[TransformSet,ex,ey,Zfinis]
	[IPress,Transform:Snapshot]
]
[iButton," Getstroke ","Grab the Stroke Data",
	[VarSet,theStroke,[StrokeGetLast]] //get the last drawn stroke
]
[PD]
[PD]
<zscriptinsert,"Widgets_Index_Include.txt">
[PD]
[PD]
[fontSetSizeSmall]\C00e0e0Digit Widget Stroke Object Revision 3.3, created by Digits\Cc0c0c0
